import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '*',
    component: () => import('@/views/404/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: 'Dashboard',
        icon: 'dashboard',
        affix: true
      }
    }]
  }
]

export const asyncRoutes = [{
    path: '/carSystem',
    component: Layout,
    alwaysShow: true, // will always show the root menu
    name: 'permission',
    meta: {
      title: '测试路由',
      icon: 'lock',
      roles: ['admin', 'editor']
    },
    children: [{
      path: 'car',
      component: () => import('@/views/car/carList/index'),
      name: 'CAR',
      meta: {
        title: '测试车辆',
        roles: ['admin', 'editor']
      }
    } ]
  },
]

const createRouter = () => new Router({
  mode: 'history', 
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
